package com.ruoyi.spm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.spm.domain.Part;
import com.ruoyi.spm.service.IPartService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 零件数据管理Controller
 *
 * @author wangxinyu
 * @date 2025-05-23
 */
@RestController
@RequestMapping("/spm/part")
public class PartController extends BaseController
{
    @Autowired
    private IPartService partService;

    /**
     * 查询零件数据管理列表
     */
    @PreAuthorize("@ss.hasPermi('spm:part:list')")
    @GetMapping("/list")
    public TableDataInfo list(Part part)
    {
        startPage();
        List<Part> list = partService.selectPartList(part);
        return getDataTable(list);
    }

    /**
     * 导出零件数据管理列表
     */
    @PreAuthorize("@ss.hasPermi('spm:part:export')")
    @Log(title = "零件数据管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Part part)
    {
        List<Part> list = partService.selectPartList(part);
        ExcelUtil<Part> util = new ExcelUtil<Part>(Part.class);
        util.exportExcel(response, list, "零件数据管理数据");
    }

    /**
     * 获取零件数据管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('spm:part:query')")
    @GetMapping(value = "/{pno}")
    public AjaxResult getInfo(@PathVariable("pno") String pno)
    {
        return success(partService.selectPartByPno(pno));
    }

    /**
     * 新增零件数据管理
     */
    @PreAuthorize("@ss.hasPermi('spm:part:add')")
    @Log(title = "零件数据管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Part part)
    {
        return toAjax(partService.insertPart(part));
    }

    /**
     * 修改零件数据管理
     */
    @PreAuthorize("@ss.hasPermi('spm:part:edit')")
    @Log(title = "零件数据管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Part part)
    {
        return toAjax(partService.updatePart(part));
    }

    /**
     * 删除零件数据管理
     */
    @PreAuthorize("@ss.hasPermi('spm:part:remove')")
    @Log(title = "零件数据管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pnos}")
    public AjaxResult remove(@PathVariable String[] pnos)
    {
        return toAjax(partService.deletePartByPnos(pnos));
    }
}
